package activiti

//import base.OpenJs
import org.activiti.engine.repository.Model

/**
 * 流程模型的扩展
 */
class ActModel implements Model {
//    Model model
    String id
    String name  //流程的中文名称
    String key  //  流程的英文名称
    String metaInfo
    Integer version=0
    String deploymentId
    String tenantId
    String category
    Date createTime
    Date lastUpdateTime
    String description  // 描述
    String status = '新建'  //状态
    String ctraterRealName //创建人 名称
    String ctraterUserName // 创建人 username
    String typeCode// 类别 编号
    String typeName// 类别 名称
    Date dateCreated//创建时间
    Date lastUpdated//最后更新的时间
    String bbms// 版本描述
//    OpenJs openJs//   发起环节的openjs,在方案保存时写入// 用于 实现一个业务只能有一个流程定义在发布中f
//    static transients = ['name', 'key', 'version', 'metaInfo', 'deploymentId', 'modelId']
    static constraints = {
        description nullable: true, maxSize: 4000
        ctraterRealName nullable: true
        ctraterUserName nullable: true
        typeCode nullable: true
        typeName nullable: true
        dateCreated nullable: true
        lastUpdated nullable: true
        category nullable: true
        createTime nullable: true
        lastUpdateTime nullable: true
        deploymentId nullable: true
        tenantId nullable: true
        version nullable: true
        bbms nullable: true
//        openJs nullable: true
    }
    static mapping = {
        id generator: 'assigned'
        version false
        key column:'key_'
    }
    String toString(){
        return  name +"("+key+")"
    }
    public ActModel() {
    }
    @Override
    String getId(){
        this.id
    }
    @Override
    String getName() {
        return this.name
    }

    @Override
    void setName(String s) {
        this.name = s
    }
    @Override
    String getKey() {
        return this.key
    }

    @Override
    void setKey(String s) {
        this.key = s
    }

    @Override
    String getCategory() {
        return this.category
    }

    @Override
    void setCategory(String s) {
        this.category = s
    }

    @Override
    Date getCreateTime() {
        return this.createTime
    }

    @Override
    Date getLastUpdateTime() {
        return this.lastUpdateTime
    }

    Integer getVersion() {
        return this?.version
    }

    @Override
    void setVersion(Integer integer) {

    }

    String getMetaInfo() {
        return this.metaInfo
    }

    @Override
    void setMetaInfo(String s) {
        this.metaInfo = s
    }

    String getDeploymentId() {
        return this.deploymentId
    }

    @Override
    void setDeploymentId(String s) {
        this.deploymentId = s
    }

    @Override
    void setTenantId(String s) {
        this.tenantId = s
    }

    @Override
    String getTenantId() {
        return this.tenantId
    }

    @Override
    boolean hasEditorSource() {
        return false
    }

    @Override
    boolean hasEditorSourceExtra() {
        return false
    }


    transient utilsService

    def buildDomain() {
        def b = [:] + this.properties
        def param = [allowformat: true, allowprecision: false]
        b = utilsService.truncProp(this, b, param) { amap ->
            amap << ['id': this.id]
            amap << ['text': this.name+" "+this.key+" "+this.bbms]
            amap << ['controlerName': this.openJs?.controlerName]
            amap << ['ywdescription': this.openJs?.description]
        }
        b
    }

    def buildDomainList(list) {
        def rds = []
        list.each {
            def b = [:] + it.properties
            def param = [allowformat: true, allowprecision: false]
            b = utilsService.truncProp(it, b, param) { amap ->
                amap << ['id': it.id]
                amap << ['text': it.name+" "+it.key+" "+it.bbms]
                amap << ['controlerName': it.openJs?.controlerName]
                amap << ['ywdescription': it.openJs?.description]
            }
            rds << b
        }
        return rds
    }
}
